#include"process.h"
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#define NUM 101
#define STYLE '#'
#define POINT '.'
#define SPACE ' '

const int pnum = 6;

//第一版，虚拟进度
//void process()
//{
//    const char * lable = "|/-\\";
//    int len = strlen(lable);
//    char bar[NUM];
//    memset(bar,'\0',sizeof(bar));
//    int cnt = 0;
//    while(cnt <= 100)
//    {
//      printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
//      fflush(stdout);
//      bar[cnt] = STYLE;
//      cnt++;
//      if(cnt == NUM) 
//      {
//          bar[cnt-1] = '\0';
//          break;
//      }
//      bar[cnt] = '>';
//      usleep(20000);
//
//    }
//    printf("\r\n");

void process(double current,double total)
{
  double rate = (current / total)*100 ;
  char bar[NUM];
  memset(bar,'\0',sizeof(bar));
  for(int i = 0;i <(int)rate;i++)
  {
      bar[i] = STYLE;

  }
  static int num = 0;
  num++;
  num %= pnum;
  char points[pnum+1];
  memset(points,'\0',sizeof(points));
  for(int i = 0;i < pnum;i++)
  {
      if(i < num)
      points[i] = POINT;
      else
      points[i] = SPACE;

  }
  printf("[%-100s][%.1lf%%]%s\r",bar,rate,points);
  fflush(stdout);
}
